package akaram.util.dice;

import java.util.Random;

/**
 * 
 * This class generate random dice rolls.
 * 
 * @author johan.paz
 *
 */
public class DiceRoller 
{
	private static Random rnd = new Random();
	
	public static int rollADice( int faces )
	{
		return rnd.nextInt(faces) + 1;
	}
	
	public static int rollDice( int number, int faces, int plus )
	{
		int resul = plus;
		
		for( int i = 0; i < number; i ++ )
		{
			resul += rollADice(faces);
		}
		
		return resul;
	}
	
	public static int rollDice( DiceThrow thr )
	{
		return DiceRoller.rollDice(thr.getNumber(),thr.getFaces(), thr.getPlus());
	}
	
	/**
	 * 
	 * Roll a group of dices in the sintax: NdF+P or P+NdF or NdF-P
	 * 
	 * @param dice
	 * @return
	 * @throws RollDiceException 
	 */
	public static int rollDice( String dice ) throws RollDiceException
	{	
		DiceThrow d = new DiceThrow(dice);
		
		return d.getThrow();
	}
	
	public static void main( String[] params )
	{
		for( String str: params )
		{
			try {
				System.out.println("D" + str + " = " + rollDice(str) );
			} catch (RollDiceException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
